#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>

int main()
{
	int ret = fork();
	if(ret < 0)
	{
		perror("fork");
		exit(1);
	}
	else if(ret == 0)
	{
		//子进程
		while(1)
		{
			sleep(1);
			std::cout<<"我是子子子进程，我的pid是: "<<getpid()<<"对应的ret的值是: "<<ret<<std::endl;
		}
	}
	else
	{
		//父进程
		while(1)
		{
			sleep(1);
			std::cout<<"我是父父父进程，我的pid是: "<<getpid()<<"对应的ret的值是: "<<ret<<std::endl;
		}
	}
	sleep(1);

	//std::cout<<"父进程开始运行, pid: "<<getpid()<<std::endl;
	//fork();//创建子进程
	//std::cout<<"子进程开始运行, pid: "<<getpid()<<std::endl;
	//chdir("/home/lfz");
	//fopen("hello.txt", "w");
	//while(true)
	//{
	//	sleep(1);
	//	std::cout<<"I am a process, my pid is "<<getpid()<<std::endl;
	//}	
	return 0;
}
